import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
import { Length, IsEmail } from 'class-validator';

export interface IUser {
  id: number
  nickname: string
  email: string
  token: string
  lastLogin: Date
}

@Entity()
export class User {
  @PrimaryGeneratedColumn()
  id: number;

  @Column({
    length: 80
  })
  @Length(4, 80)
  nickname: string;

  @Column({
    length: 80,
    unique: true,
  })
  @Length(4, 80)
  token: string;

  @Column()
  lastLogin: Date;

  @Column({
    length: 100,
    // unique: true, // 通过策略限制Email只能上传一次
  })
  @Length(10, 100)
  @IsEmail()
  email: string;
}